<feed xmlns='http://www.w3.org/2005/Atom'>
<title>mutt-alias-auto-add/src/tests.rs, branch v0.0.1</title>
<subtitle>A display filter for Mutt to automatically add aliases for emails that you read</subtitle>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/'/>
<entry>
<title>test: Fix `write_to_file` race condition</title>
<updated>2016-04-24T13:39:14+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T13:39:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=79e78aaa7c0c77064264ffdad0c3172aa0f5c376'/>
<id>79e78aaa7c0c77064264ffdad0c3172aa0f5c376</id>
<content type='text'>
Have each `write_to_file` test pass in a custom filename to the helper
function. This way each test has its own file to deal with, eliminating
the race condition when running tests in parallel (the default).
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Have each `write_to_file` test pass in a custom filename to the helper
function. This way each test has its own file to deal with, eliminating
the race condition when running tests in parallel (the default).
</pre>
</div>
</content>
</entry>
<entry>
<title>Write alias even if we haven't found a matching one</title>
<updated>2016-04-24T13:31:25+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T13:31:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=2e844b5c528a39e75702d0b412b0396080fa103e'/>
<id>2e844b5c528a39e75702d0b412b0396080fa103e</id>
<content type='text'>
If we get an `AliasSearchError::NotFound` error we still want to write
the alias to the file. After all, it's an email we haven't encountered
yet so we should store an alias for it.

If the email exists, we can do what we were doing before and change the
current alias to be unique.

Rename our "append" `write_to_file` test method to be a little more
clear about its purpose.

Create a new `write_to_file` test function that tests the case we're
adding here.

Note that having these two tests together seems to cause a race
condition because they're both using the same temporary test file. If we
run tests with `RUST_TEST_THREADS=1 cargo test` then they pass. Will see
about fixing that next.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If we get an `AliasSearchError::NotFound` error we still want to write
the alias to the file. After all, it's an email we haven't encountered
yet so we should store an alias for it.

If the email exists, we can do what we were doing before and change the
current alias to be unique.

Rename our "append" `write_to_file` test method to be a little more
clear about its purpose.

Create a new `write_to_file` test function that tests the case we're
adding here.

Note that having these two tests together seems to cause a race
condition because they're both using the same temporary test file. If we
run tests with `RUST_TEST_THREADS=1 cargo test` then they pass. Will see
about fixing that next.
</pre>
</div>
</content>
</entry>
<entry>
<title>`write_to_file` test: Extract append lines to closure</title>
<updated>2016-04-24T12:44:04+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T12:44:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=7c9439bc11ae95b6f2da59eabf2950d15df4d558'/>
<id>7c9439bc11ae95b6f2da59eabf2950d15df4d558</id>
<content type='text'>
We want to be able to write a test that ensures aliases can be written
to the file even if they don't already exist.

To do this, I want to be able to reuse the code in the helper function.
We can't use the code that appends to the file because this is relevant
only to the `alias_write_to_file_must_write_given_alias_to_file` test
(which I just realised should actually be renamed to something more
specific).

In order to run this code without requiring it to be in the helper
function, extract it to a closure that gets passed to the helper.

We need to pass `alias` into the function explicitly in order to use it
otherwise we get an error on an immutable borrow.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
We want to be able to write a test that ensures aliases can be written
to the file even if they don't already exist.

To do this, I want to be able to reuse the code in the helper function.
We can't use the code that appends to the file because this is relevant
only to the `alias_write_to_file_must_write_given_alias_to_file` test
(which I just realised should actually be renamed to something more
specific).

In order to run this code without requiring it to be in the helper
function, extract it to a closure that gets passed to the helper.

We need to pass `alias` into the function explicitly in order to use it
otherwise we get an error on an immutable borrow.
</pre>
</div>
</content>
</entry>
<entry>
<title>Extract `alias_write_to_file` test function contents to helper</title>
<updated>2016-04-24T10:36:32+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T10:36:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=66193af4e53799299c04ecf8715e44693f1bff8a'/>
<id>66193af4e53799299c04ecf8715e44693f1bff8a</id>
<content type='text'>
Create a new helper function that does the work of
`alias_write_to_file_must_write_given_alias_to_file`. We want to be able
to add another test of the `write_to_file` method that does the same
thing but for non-preexisting aliases. Making a helper method will allow
us to avoid duplicating work.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Create a new helper function that does the work of
`alias_write_to_file_must_write_given_alias_to_file`. We want to be able
to add another test of the `write_to_file` method that does the same
thing but for non-preexisting aliases. Making a helper method will allow
us to avoid duplicating work.
</pre>
</div>
</content>
</entry>
<entry>
<title>Move `Alias` to separate alias module</title>
<updated>2016-04-24T09:40:45+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T09:40:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=afc01ecb67dd978879d423866d33ac0c526151f4'/>
<id>afc01ecb67dd978879d423866d33ac0c526151f4</id>
<content type='text'>
Take all of our Alias code, functions, errors, etc. and move them into
their own module. This removes some clutter from our `main.rs` file and
makes things better organised. Now all the alias code lives in its own
dedicated place.

Update our test file imports to match this change.

Updates to alias code:

* Reordered imports alphabetically
* Made `Alias` public
* Made `AliasSearchError` public
* Made all methods on `Alias` public
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Take all of our Alias code, functions, errors, etc. and move them into
their own module. This removes some clutter from our `main.rs` file and
makes things better organised. Now all the alias code lives in its own
dedicated place.

Update our test file imports to match this change.

Updates to alias code:

* Reordered imports alphabetically
* Made `Alias` public
* Made `AliasSearchError` public
* Made all methods on `Alias` public
</pre>
</div>
</content>
</entry>
<entry>
<title>Move `write_alias` function to `Alias#write_to_file`</title>
<updated>2016-04-24T09:17:19+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T09:17:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=2d1f7031f03194fbceffc15b1d6376abea243e22'/>
<id>2d1f7031f03194fbceffc15b1d6376abea243e22</id>
<content type='text'>
Expand the responsibility of `Alias#write_to_file` so that it performs
what it used to do plus all of what `write_alias` did.

This allows us to consolidate the functionality into a single method,
and move it into the `Alias` implementation.

The change required some modification to our `write_to_file` test:

* Create our test alias as mutable
* Write a new alias to the test file based on our test alias but with a
  different email. This allows the `write_to_file` method to work
  without erroring with an `AliasSearchError::NotFound`.
* Needed to `derive(Clone)` on `Alias` in order to be able to easily
  clone it into the new near-duplicate alias.
* Change our `unwrap()` calls to `expect()` to make it easier to see
  where exactly we panicked. Otherwise I didn't really have any way of
  knowing.
* Add some comments for clarity
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Expand the responsibility of `Alias#write_to_file` so that it performs
what it used to do plus all of what `write_alias` did.

This allows us to consolidate the functionality into a single method,
and move it into the `Alias` implementation.

The change required some modification to our `write_to_file` test:

* Create our test alias as mutable
* Write a new alias to the test file based on our test alias but with a
  different email. This allows the `write_to_file` method to work
  without erroring with an `AliasSearchError::NotFound`.
* Needed to `derive(Clone)` on `Alias` in order to be able to easily
  clone it into the new near-duplicate alias.
* Change our `unwrap()` calls to `expect()` to make it easier to see
  where exactly we panicked. Otherwise I didn't really have any way of
  knowing.
* Add some comments for clarity
</pre>
</div>
</content>
</entry>
<entry>
<title>Move `find_alias_in_file` function to `Alias#find_in_file`</title>
<updated>2016-04-24T08:43:00+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-24T08:43:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=c67fdff0c3cda883b5bf577988e1c555931969cf'/>
<id>c67fdff0c3cda883b5bf577988e1c555931969cf</id>
<content type='text'>
Makes more sense for this function to live in a method on `Alias`
because it operates directly on an alias.

Refactor our tests and code to support this new organisation.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Makes more sense for this function to live in a method on `Alias`
because it operates directly on an alias.

Refactor our tests and code to support this new organisation.
</pre>
</div>
</content>
</entry>
<entry>
<title>tests: Make constant name uppercase</title>
<updated>2016-04-22T13:35:19+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-22T13:35:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=4eff98a64efd573a2a77a5e8f6302860085a289c'/>
<id>4eff98a64efd573a2a77a5e8f6302860085a289c</id>
<content type='text'>
The test compiler complained that I should make my constant uppercase.
Do this to eliminate our compiler warnings.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The test compiler complained that I should make my constant uppercase.
Do this to eliminate our compiler warnings.
</pre>
</div>
</content>
</entry>
<entry>
<title>Alias#write_to_file: Fix append and ending newline</title>
<updated>2016-04-22T12:24:15+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-22T12:24:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=ff0b31cfe68b2bc7318a98827d812e32deff0b4c'/>
<id>ff0b31cfe68b2bc7318a98827d812e32deff0b4c</id>
<content type='text'>
Changed the test to use a file with multiple alias lines for a more
real-world scenario. Achieving this by copying the `testdata/aliases`
file into a new temporary test file instead of creating a new blank
file.

Then needed to change our assertion so that we get the correct line from
the file to compare on. This is always the last line in the file. Note
that `.len() - 2` is used because `.len() - 1` is the final newline.

The test change revealed two errors in my code:

1. I needed to open the file for appending, not just for writing.
2. A newline needs to be appended to the end of the file (otherwise all
   our aliases get written to the same line).

Fix the errors.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Changed the test to use a file with multiple alias lines for a more
real-world scenario. Achieving this by copying the `testdata/aliases`
file into a new temporary test file instead of creating a new blank
file.

Then needed to change our assertion so that we get the correct line from
the file to compare on. This is always the last line in the file. Note
that `.len() - 2` is used because `.len() - 1` is the final newline.

The test change revealed two errors in my code:

1. I needed to open the file for appending, not just for writing.
2. A newline needs to be appended to the end of the file (otherwise all
   our aliases get written to the same line).

Fix the errors.
</pre>
</div>
</content>
</entry>
<entry>
<title>Add `Alias#write_to_file`</title>
<updated>2016-04-22T12:03:47+00:00</updated>
<author>
<name>Teddy Wing</name>
</author>
<published>2016-04-22T12:03:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.teddywing.com/mutt-alias-auto-add/commit/?id=483b297db9604f7c1d8ae63e6ab4aadec70ce1cb'/>
<id>483b297db9604f7c1d8ae63e6ab4aadec70ce1cb</id>
<content type='text'>
Writes the alias to a given file.

Thinking I should modify the test so that we can know it works with
multiple alias lines.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Writes the alias to a given file.

Thinking I should modify the test so that we can know it works with
multiple alias lines.
</pre>
</div>
</content>
</entry>
</feed>
